<template>
    <mian-layout @refresh="resetForm('search_data')">
        <template v-slot:conTop>
            <el-form size="mini" :inline="true" :model='search' ref="search_data" class="demo-form-inline search-form">
                <el-form-item label="NFT名称" prop="title">
					<el-input v-model="search.title" placeholder="NFT名称"></el-input>
				</el-form-item>
                <el-form-item label="创作者" prop="creatorAddress">
					<el-input v-model="search.creatorAddress" placeholder="创作者ID/账号"></el-input>
				</el-form-item>
                <el-form-item label="出售者" prop="ownerAddress">
					<el-input v-model="search.ownerAddress" placeholder="出售者ID/账号"></el-input>
				</el-form-item>
                <el-form-item label="交易发布时间" prop="dataTime">
                        <el-date-picker v-model="dataTime" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" value-format="yyyy-MM-dd HH:mm" />
                    </el-form-item>
                <el-form-item>
					<el-button type="primary" plain  icon="el-icon-search" @click="doSearch">搜索</el-button>
                        <el-button icon="el-icon-refresh-right" @click="resetForm('search_data')">重置</el-button>
				</el-form-item>
            </el-form>   
        </template>
        <div class="myanfbtntabbox">
            <el-tabs v-model="search.sellStatus" @tab-click="reSetData">
                <el-tab-pane :label="`拍卖预告`" name="0"></el-tab-pane>
                <el-tab-pane :label="`拍卖中`" name="10"></el-tab-pane>
                <el-tab-pane :label="`交易成功`" name="20"></el-tab-pane>
                <el-tab-pane :label="`交易失败`" name="30"></el-tab-pane>
            </el-tabs>
            <!-- <div class="mybtn">
                <el-button type="success" size="small" icon="el-icon-plus" @click="goAdd">发布新商品</el-button>
            </div> -->
        </div>
        <my-table :loading="loading" :lists="tableData" @selectionChange="tableSelect" @pageChange="handleChange" :sequence="true" :page='page'>
            <el-table-column property="title" label="NFT图片" align='left'>
                <template slot-scope="scope">
                    <div class="tbimgbox">
                        <img :src="scope.row.nftImage" alt="">
                    </div>
                </template> 
            </el-table-column>
            <el-table-column property="title" label="NFT名称"  align='center'></el-table-column>
            <el-table-column property="chainName" label="NFT主链"  align='center'></el-table-column>
            <el-table-column property="contractAddress" label="合约地址"  align='center'></el-table-column>
            <el-table-column property="publishingPlatform" label="发布平台"  align='center'></el-table-column>
            <el-table-column property="settlementCurrency" label="结算货币"  align='center'></el-table-column>
            <el-table-column property="initialPrice" label="NFT初始价" align='center' width="100">
                <template slot-scope="scope">
                    {{scope.row.initialPrice?scope.row.initialPrice.decimalTwoString:'--'}}
                </template>
            </el-table-column>
            <el-table-column property="creatorAddress" label="创作者ID/钱包地址"  align='center'></el-table-column>
            <el-table-column property="ownerAddress" label="出售者ID/钱包地址"  align='center'></el-table-column>
            <el-table-column property="startTime" label="拍卖开始时间"  align='center'></el-table-column>
            <el-table-column property="endTime" label="拍卖结束时间"  align='center'></el-table-column>
            <el-table-column property="createTime" label="交易发布时间"  align='center'></el-table-column>
      
            <el-table-column prop="operation" align='center' label="操作" :width="100">
                <template slot-scope="scope">
                    <el-button size="mini" icon="el-icon-search" @click="goLook(scope.row)">查看</el-button>
                </template>
            </el-table-column>
        </my-table>
    </mian-layout>
</template>
<script>
import myTable from '@/components/public/myTable';
import goodsCategory from '@/components/public/goodsCategory.vue';
import {
  get_trade_list
} from '@/api/collext'
import myDialog from '@/components/public/myDialog';
export default {
    components:{
      myTable,
      goodsCategory,
      myDialog
    },
    data(){
        return{
            search:{
                title:'',
                ownerAddress:'',
                creatorAddress:'',
                createTimeEnd: "",
                createTimeBegin: "",
                sellStatus:0
            },
            dataTime:'',
            page:{
                pageSize:10,
                pageIndex:1,
			    total:0,
            },
            loading:true,
            tableData:[],
            multipleSelectionIds:[],
            totalRow:{}
        }
    },
    created(){
        this.getList()
    },
    mounted(){
        
    },
    methods:{
        getList(callback){
            this.loading = true
            if(this.dataTime){
                this.search.createTimeBegin = this.dataTime[0]
                this.search.createTimeEnd = this.dataTime[1]
            }
            get_trade_list({
                limit: this.page.pageSize,
                page: this.page.pageIndex,
                sellModel:1, // 交易类型 0 寄售 1 竞拍
                ...this.search
            }).then(res=>{
                this.loading = false
                this.tableData = res.data
                this.page.total = res.total
                this.totalRow = res.totalRow
                callback && callback()
            })
        },
        doSearch(){
            this.page.pageIndex = 1;
            this.getList();
        },
        refreshData(){
            this.page.pageIndex = 1;
            this.getList();
        },
        tableSelect(data){
            console.log("GGGG:",data)
        },
        handleChange(index) {
            this.page.pageIndex = index;
            this.getList();
        },
        reSetData(){
            this.page.pageIndex = 1;
            this.getList();
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
            this.dataTime = []
            for (const key in this.search) {
               this.search[key] = ''
            }
            this.search.sellStatus = '0'
            this.page.pageIndex = 1
            this.getList()
        },
        // goEdit(item,onlyLook){
        //     //sessionStorage.setItem('details',JSON.stringify(item))
        //     this.$store.commit('tagsView/SET_REGETDATA',this.getList)  // 设置需要刷新的方法，修改后返回需要刷新数据
        //     this.$router.push(`/goods/add?id=${item.sellRecordId}&onlyLook=${onlyLook}`)
        // },
        // goAdd(){
        //     this.$store.commit('tagsView/SET_REGETDATA',this.getList)  // 设置需要刷新的方法，修改后返回需要刷新数据
        //     this.$router.push('/goods/add')
        // },
        goLook(item){
            this.$store.commit('tagsView/SET_REGETDATA',this.getList)  // 设置需要刷新的方法，修改后返回需要刷新数据
            this.$router.push(`/trade/detail/1/${item.sellRecordId}`)
        }
    }
}
</script>

<style lang="scss" scoped>
    .myanfbtntabbox{
        position: relative;
        z-index: 10;
        .mybtn{
            position: absolute;
            z-index: 10;
            right: 0;
            top: 0;
        }
    }
    .tbimgbox{
        display: flex;
        align-items: center;
        justify-content: center;
        img{
            width: 50px!important;
            height: 50px!important;
            max-width: 200px;
        }
    }
</style>